package com.ruoyi.system.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ruoyi.system.entity.NucleicAcid;
import com.ruoyi.system.mapper.NucleicAcidMapper;
import com.ruoyi.system.service.NucleicAcidService;
import org.springframework.stereotype.Service;

import java.util.List;

/**
* @author ruochen
* @description 针对表【nucleic_acid(核酸表)】的数据库操作Service实现
* @createDate 2023-11-20 11:05:53
*/
@Service
public class NucleicAcidServiceImpl extends ServiceImpl<NucleicAcidMapper, NucleicAcid>
    implements NucleicAcidService{

    @Override
    public List<NucleicAcid> getNucleicAcidByIsolationId(Long userId) {
        LambdaQueryWrapper<NucleicAcid> nucleicAcidLambdaQueryWrapper = new LambdaQueryWrapper<>();
        nucleicAcidLambdaQueryWrapper.eq(NucleicAcid::getUserId,userId);
        // 按照创建时间倒序排列
        nucleicAcidLambdaQueryWrapper.orderByDesc(NucleicAcid::getCreateTime);
        List<NucleicAcid> nucleicAcids = this.list(nucleicAcidLambdaQueryWrapper);
        if (nucleicAcids != null && nucleicAcids.size() > 0) {
            return nucleicAcids;
        }else {
            throw new RuntimeException("未查询到该用户的核酸信息");
        }
    }

    @Override
    public List<NucleicAcid> getNucleicAcidList(NucleicAcid nucleicAcid) {
        LambdaQueryWrapper<NucleicAcid> nucleicAcidLambdaQueryWrapper = new LambdaQueryWrapper<>();
        // 按照检测时间倒序排列
        nucleicAcidLambdaQueryWrapper.orderByDesc(NucleicAcid::getDetectionTime);
        if (nucleicAcid.getUserId()!=null){
            nucleicAcidLambdaQueryWrapper.eq(NucleicAcid::getUserId,nucleicAcid.getUserId());
        }
        if (nucleicAcid.getTestingLocation()!=null){
            nucleicAcidLambdaQueryWrapper.like(NucleicAcid::getTestingLocation,nucleicAcid.getTestingLocation());
        }
        if (nucleicAcid.getDetectionTime()!=null){
            nucleicAcidLambdaQueryWrapper.like(NucleicAcid::getDetectionTime,nucleicAcid.getDetectionTime());
        }
        if (nucleicAcid.getDetectionResult()!=null){
            nucleicAcidLambdaQueryWrapper.eq(NucleicAcid::getDetectionResult,nucleicAcid.getDetectionResult());
        }
       return this.list(nucleicAcidLambdaQueryWrapper);
    }


}




